﻿////Javascript String Dictionary Object
function jsStringDictionary()
{
		//our actual dictionary
		this.obj = new Object();
		
		//the number of key value pairs currently in here
		this.count = 0;
		
		//adds key,value pair
		jsStringDictionary.prototype.add = _sd_Add;
		
		//removes key,value pair
		jsStringDictionary.prototype.remove = _sd_Remove;
		
		//removes all pairs
		jsStringDictionary.prototype.removeAll = _sd_RemoveAll;
		
		//gets an array of values
		jsStringDictionary.prototype.getValues = _sd_GetValues;
		
		//gets an array of keys
		jsStringDictionary.prototype.getKeys = _sd_GetKeys;
		
		//gets a value from a key
		jsStringDictionary.prototype.getVal = _sd_GetVal;
		
		//sets a value from an existing key
		jsStringDictionary.prototype.setVal = _sd_SetVal;		
		
		//checks if the dictionary contains a key
		jsStringDictionary.prototype.containsKey = _sd_ContainsKey;
}

//add key value pair
function _sd_Add(_key,obj)
{
	//make sure its a string we are working with
	var _szKey = String(_key);
	//if it already exists reset its value
	if(this.containsKey(_szKey))
	{
		this.setVal(_szKey);
		return false;
	}
	//
	this.obj[_szKey]=obj;
	this.count++;
	return true;
}

//remove a key value pair
function _sd_Remove(_key)
{
	//make sure its a string
	var _szKey = String(_key);
	//is there something to remove?
	if(!this.containsKey(_szKey))
		return false;
	delete this.obj[_szKey];
	this.count--;
}

//remove everything
function _sd_RemoveAll()
{
	for(var _key in this.obj)
		delete this.obj[_key];
	this.count=0;
}

//get values as an array
function _sd_GetValues()
{
	var _return = new Array();
	for(var _key in this.obj)
		_return.push(this.obj[_key]);
	return _return;
}

//get keys as an array
function _sd_GetKeys()
{
	var _return = new Array();
	for(var _key in this.obj)
		_return.push(_key);
	return _return;
}

//get a value froma  key
function _sd_GetVal(_key)
{
	return this.obj[String(_key)];
}

//set a value from a key
function _sd_SetVal(_key,_val)
{
	var _szKey = String(_key);
	if(this.containsKey(_szKey))
		this.obj[_szKey]=_val;
	else
		this.add(_key,_val);
}

//check if a key exists
function _sd_ContainsKey(_key)
{
	return (this.obj[_key])?true:false
}
